<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<style>
.invoices {
	width: 100%;
	padding-top: 10px;
	padding-bottom: 10px;
	border-top: 1px solid #dddddd;
	padding-top: 10px;
}
</style>

<c:if test="${!empty invoices}">

	<h1>Invoices</h1>

	<button class="btn btn-primary btn" data-toggle="modal"
		data-target="#newModal">New Invoice</button><br/>
	<div class="modal fade" id="newModal">
		<div class="modal-dialog" style="width: 350px;">
			<form method="post" action="invoices/new">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">&times;</button>
						<h4 class="modal-title">New Invoice</h4>
					</div>
					<div class="modal-body">
						<br /> <select class="form-control" name="userInvoice">
							<option disabled selected="selected">Select client</option>
							<c:forEach items="${clients}" var="user">
								<option value="${user.id}">${user.firstname}</option>
							</c:forEach>
						</select>
					</div>
					<div class="modal-footer">
						<input type="submit" class="btn btn-primary" value="Save" />
						<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>

					</div>
				</div>
			</form>
		</div>
		<!-- /.modal-content -->
	</div>

	<div class="row invoices">
		<div class="col-md-1">
			<b>Number</b>
		</div>
		<div class="col-md-2">
			<b>User</b>
		</div>
		<div class="col-md-2">
			<b>Date Activation</b>
		</div>
		<div class="col-md-2">
			<b>Sum</b>
		</div>
		<div class="col-md-3">
			<b>Type Payment</b>
		</div>
		<div class="col-md-2">
			<b>Status</b>
		</div>
	</div>
	<c:forEach items="${invoices}" var="invoice">
		<div class="row invoices">
			<form method="post" action="invoices/replay">
				<div class="col-md-1">${invoice.id}
					<input type="hidden" value="${invoice.id}" name="invoice_id" />
				</div>
				<div class="col-md-2">${invoice.user.firstname}
					${invoice.user.lastname}</div>
				<div class="col-md-2">
					<fmt:formatDate value="${invoice.dateActivation}"
						pattern=" MM-dd-yyyy" />
				</div>
				<div class="col-md-2">${invoice.sum}</div>

				<div class="col-md-3">
					<c:choose>
						<c:when test="${invoice.isReplay==true}">
						${invoice.typePayment.name}
						</c:when>
						<c:when test="${invoice.isReplay==false}">
								---
							</c:when>
					</c:choose>
				</div>

				<div class="col-md-2">
					<c:choose>
						<c:when test="${invoice.isReplay==false}">
								Don't replay
							</c:when>
						<c:when test="${invoice.isReplay==true}">
						Reply
						</c:when>
					</c:choose>
				</div>
			</form>
		</div>

	</c:forEach>

</c:if>
